
package integral_record

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/integral_record"
    integral_recordReq "github.com/flipped-aurora/gin-vue-admin/server/model/integral_record/request"
)

type IntegralRecordsService struct {}
// CreateIntegralRecords 创建integralRecords表记录
// Author [yourname](https://github.com/yourname)
func (integralRecordsService *IntegralRecordsService) CreateIntegralRecords(integralRecords *integral_record.IntegralRecords) (err error) {
	err = global.GVA_DB.Create(integralRecords).Error
	return err
}

// DeleteIntegralRecords 删除integralRecords表记录
// Author [yourname](https://github.com/yourname)
func (integralRecordsService *IntegralRecordsService)DeleteIntegralRecords(id string) (err error) {
	err = global.GVA_DB.Delete(&integral_record.IntegralRecords{},"id = ?",id).Error
	return err
}

// DeleteIntegralRecordsByIds 批量删除integralRecords表记录
// Author [yourname](https://github.com/yourname)
func (integralRecordsService *IntegralRecordsService)DeleteIntegralRecordsByIds(ids []string) (err error) {
	err = global.GVA_DB.Delete(&[]integral_record.IntegralRecords{},"id in ?",ids).Error
	return err
}

// UpdateIntegralRecords 更新integralRecords表记录
// Author [yourname](https://github.com/yourname)
func (integralRecordsService *IntegralRecordsService)UpdateIntegralRecords(integralRecords integral_record.IntegralRecords) (err error) {
	err = global.GVA_DB.Model(&integral_record.IntegralRecords{}).Where("id = ?",integralRecords.Id).Updates(&integralRecords).Error
	return err
}

// GetIntegralRecords 根据id获取integralRecords表记录
// Author [yourname](https://github.com/yourname)
func (integralRecordsService *IntegralRecordsService)GetIntegralRecords(id string) (integralRecords integral_record.IntegralRecords, err error) {
	err = global.GVA_DB.Where("id = ?", id).First(&integralRecords).Error
	return
}
// GetIntegralRecordsInfoList 分页获取integralRecords表记录
// Author [yourname](https://github.com/yourname)
func (integralRecordsService *IntegralRecordsService)GetIntegralRecordsInfoList(info integral_recordReq.IntegralRecordsSearch) (list []integral_record.IntegralRecords, total int64, err error) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
    // 创建db
	db := global.GVA_DB.Model(&integral_record.IntegralRecords{})
    var integralRecordss []integral_record.IntegralRecords
    // 如果有条件搜索 下方会自动创建搜索语句
	err = db.Count(&total).Error
	if err!=nil {
    	return
    }

	if limit != 0 {
       db = db.Limit(limit).Offset(offset)
    }

	err = db.Find(&integralRecordss).Error
	return  integralRecordss, total, err
}
func (integralRecordsService *IntegralRecordsService)GetIntegralRecordsPublic() {
    // 此方法为获取数据源定义的数据
    // 请自行实现
}
